package com.offer;


import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

public class Test45 {

    public String minNumber(int[] nums) {
        List<String> numsArray = new ArrayList<>(nums.length);

        for (int i = 0; i < nums.length; i++) {
            numsArray.add(String.valueOf(nums[i]));
        }

        numsArray.sort(new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return (o1 + o2).compareTo(o2 + o1);
            }
        });

        StringBuilder stringBuilder = new StringBuilder();

        for (String s : numsArray) {
            stringBuilder.append(s);
        }

        return stringBuilder.toString();
    }

    public static void main(String[] args) {
        Test45 test = new Test45();
        System.out.println(test.minNumber(new int[]{3, 30, 34, 5, 9}));
    }

}
